/**
 * @Author: wangliuyang
 * @Date: 2021/9/5 11:00
 * @Description:905. 按奇偶排序数组
 */
public class Solution_905 {
    public int[] sortArrayByParity(int[] nums) {
        int L = -1;
        for (int i = 0; i < nums.length; i++) {
            if ((nums[i] & 1) == 0 && ++L != i){
                swap(nums,i,L);
            }
        }
        return nums;
    }

    private void swap(int[] nums, int i, int l) {
        nums[i] = nums[i] ^ nums[l];
        nums[l] = nums[i] ^ nums[l];
        nums[i] = nums[i] ^ nums[l];
    }
}
